package edu.algo3.algoThief.vista;

import edu.algo3.algoThief.domain.Juego;
import edu.algo3.algoThief.domain.OrdenDeArresto;
import edu.algo3.algoThief.util.Constants;

@SuppressWarnings("serial")
public class VentanaOrdenDeArresto extends javax.swing.JFrame {

	// Variables declaration - do not modify 
    private VentanaCiudadActual ventanaCiudadActual;
    private javax.swing.JButton botonAtras;
    private javax.swing.JButton botonBuscarSospechosos;
    private javax.swing.JButton botonemitirOrdendeArresto;
    private javax.swing.JComboBox comboBoxCabello;
    private javax.swing.JComboBox comboBoxHobby;
    private javax.swing.JComboBox comboBoxSenia;
    private javax.swing.JComboBox comboBoxSexo;
    private javax.swing.JComboBox comboBoxVehiculo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel labelCabelloTitulo2;
    private javax.swing.JLabel labelHobbyTitulo;
    private javax.swing.JLabel labelOrdenDeArrestoTitulo;
    private javax.swing.JLabel labelSeniaTitulo4;
    private javax.swing.JLabel labelSexoTitulo;
    private javax.swing.JLabel labelVehiculoTitulo5;
    private javax.swing.JList listaDeSospechososPosibles;
	
    public VentanaOrdenDeArresto(VentanaCiudadActual ventanaCiudadActual) {
        initComponents();
        this.ventanaCiudadActual = ventanaCiudadActual;
    }


    private void initComponents() {

        labelOrdenDeArrestoTitulo = new javax.swing.JLabel();
        comboBoxSexo = new javax.swing.JComboBox();
        labelSexoTitulo = new javax.swing.JLabel();
        comboBoxHobby = new javax.swing.JComboBox();
        labelHobbyTitulo = new javax.swing.JLabel();
        comboBoxCabello = new javax.swing.JComboBox();
        labelCabelloTitulo2 = new javax.swing.JLabel();
        comboBoxSenia = new javax.swing.JComboBox();
        labelSeniaTitulo4 = new javax.swing.JLabel();
        comboBoxVehiculo = new javax.swing.JComboBox();
        labelVehiculoTitulo5 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        listaDeSospechososPosibles = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        botonemitirOrdendeArresto = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        botonAtras = new javax.swing.JButton();
        botonBuscarSospechosos = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        labelOrdenDeArrestoTitulo.setFont(new java.awt.Font("Stencil", 0, 18)); // NOI18N
        labelOrdenDeArrestoTitulo.setText(Constants.TITULO_VENTANA_ORDEN_DE_ARRESTO);

        comboBoxSexo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Desconocido", "Masculino", "Femenino" }));

        labelSexoTitulo.setText(Constants.SEXO_TITULO);

        comboBoxHobby.setModel(new javax.swing.DefaultComboBoxModel(new String[] { Constants.CARACTERISTICA_DESCONOCIDA, Constants.HOBBY_TENIS, Constants.HOBBY_MUSICA, 
        		Constants.HOBBY_ALPINISMO, Constants.HOBBY_PARACAIDISMO, Constants.HOBBY_NATACION, Constants.HOBBY_CROQUET }));

        labelHobbyTitulo.setText(Constants.HOBBY_TITULO);

        comboBoxCabello.setModel(new javax.swing.DefaultComboBoxModel(new String[] {  Constants.CARACTERISTICA_DESCONOCIDA, Constants.CABELLO_CASTANIO, 
        		Constants.CABELLO_RUBIO, Constants.CABELLO_ROJO, Constants.CABELLO_NEGRO }));

        labelCabelloTitulo2.setText(Constants.CABELLO_TITULO);

        comboBoxSenia.setModel(new javax.swing.DefaultComboBoxModel(new String[] { Constants.CARACTERISTICA_DESCONOCIDA, Constants.SENIA_ANILLO, 
        		Constants.SENIA_TATUAJE, Constants.SENIA_CICATRIZ, Constants.SENIA_JOYAS }));

        labelSeniaTitulo4.setText(Constants.SENIA_TITULO);

        comboBoxVehiculo.setModel(new javax.swing.DefaultComboBoxModel(new String[] {Constants.CARACTERISTICA_DESCONOCIDA, "Descapotable", "Limusina", "Deportivo", "Moto" }));

        labelVehiculoTitulo5.setText(Constants.VEHICULO_TITULO);

//        listaDeSospechososPosibles.setModel(new javax.swing.AbstractListModel() {
//            String[] strings = { " " };
//            public int getSize() { return strings.length; }
//            public Object getElementAt(int i) { return strings[i]; }
//        });
//        jScrollPane1.setViewportView(listaDeSospechososPosibles);

        jLabel1.setText("Posibles sospechosos");

        botonemitirOrdendeArresto.setText("Emitir orden de arresto");
        botonemitirOrdendeArresto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonemitirOrdendeArrestoActionPerformed(evt);
            }
        });

        jLabel2.setText(Constants.MENSAJE_PARA_EMITIR_ORDEN_DE_ARRESTO);

        botonAtras.setBackground(new java.awt.Color(139, 27, 27));
        botonAtras.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        botonAtras.setForeground(new java.awt.Color(255, 255, 255));
        botonAtras.setText(Constants.ATRAS);
        botonAtras.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAtrasActionPerformed(evt);
            }
        });

        botonBuscarSospechosos.setText(Constants.MENSAJE_BUSCAR_SOSPECHOSOS);
        botonBuscarSospechosos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonbotonBuscarSospechososActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(9, 9, 9)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(labelSeniaTitulo4)
                                            .addComponent(comboBoxSenia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(comboBoxCabello, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(labelSexoTitulo)
                                            .addComponent(comboBoxSexo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(labelHobbyTitulo)
                                            .addComponent(comboBoxHobby, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(labelCabelloTitulo2)
                                            .addComponent(comboBoxVehiculo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(15, 15, 15))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addComponent(labelVehiculoTitulo5)
                                        .addGap(61, 61, 61)))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel1)
                                    .addComponent(botonemitirOrdendeArresto)
                                    .addGroup(layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 4, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 262, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(labelOrdenDeArrestoTitulo))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(botonBuscarSospechosos)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(botonAtras)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelOrdenDeArrestoTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(labelSexoTitulo)
                        .addGap(11, 11, 11)
                        .addComponent(comboBoxSexo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(labelHobbyTitulo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(comboBoxHobby, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(labelCabelloTitulo2)
                        .addGap(0, 0, 0)
                        .addComponent(comboBoxCabello, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(labelSeniaTitulo4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(comboBoxSenia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(labelVehiculoTitulo5))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botonemitirOrdendeArresto)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(comboBoxVehiculo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(botonAtras)
                    .addComponent(botonBuscarSospechosos))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>                        

    private void botonemitirOrdendeArrestoActionPerformed(java.awt.event.ActionEvent evt) {
        String apellidoDelSospechoso = (String) listaDeSospechososPosibles.getSelectedValue();
        Juego.getInstance().getJugador().emitirOrdenDeArresto(apellidoDelSospechoso);
        //TODO: POPUP QUE AVISE QUE SE EMITIO LA ORDEN DE ARRESTO
        this.setVisible(Boolean.FALSE);
        if (Juego.getInstance().getCondicionDeTriunfo().haPerdido()){
            new PanelJuegoTerminado(this.ventanaCiudadActual, Constants.JUEGO_TERMINADO, Constants.SE_HA_ACABADO_EL_TIEMPO);
        }
        
    }                                                         

    private void botonbotonBuscarSospechososActionPerformed(java.awt.event.ActionEvent evt) {
        
        String sexoSeleccionado = (String) comboBoxSexo.getSelectedItem();
        String hobbySeleccionado = (String) comboBoxHobby.getSelectedItem();
        String cabelloSeleccionado = (String) comboBoxCabello.getSelectedItem();
        String seniaSeleccionada = (String) comboBoxSenia.getSelectedItem();
        String vehiculoSeleccionado = (String) comboBoxVehiculo.getSelectedItem();
        
        OrdenDeArresto ordenDeArresto = Juego.getInstance().getJugador().getOrdenDeArresto();
        
        if (!Constants.CARACTERISTICA_DESCONOCIDA.equals(sexoSeleccionado)){
            ordenDeArresto.setSexo(sexoSeleccionado);
        } else {
            ordenDeArresto.setSexo(Constants.VACIO);
        }
        if (!Constants.CARACTERISTICA_DESCONOCIDA.equals(hobbySeleccionado)){
            ordenDeArresto.setHobby(hobbySeleccionado);
        } else {
            ordenDeArresto.setHobby(Constants.VACIO);
        }
        if (!Constants.CARACTERISTICA_DESCONOCIDA.equals(cabelloSeleccionado)){
            ordenDeArresto.setCabello(cabelloSeleccionado);
        } else {
            ordenDeArresto.setCabello(Constants.VACIO);
        }
        if (!Constants.CARACTERISTICA_DESCONOCIDA.equals(seniaSeleccionada)){
            ordenDeArresto.setSenia(seniaSeleccionada);
        } else {
            ordenDeArresto.setSenia(Constants.VACIO);
        }
        if (!Constants.CARACTERISTICA_DESCONOCIDA.equals(vehiculoSeleccionado)){
            ordenDeArresto.setVehiculo(vehiculoSeleccionado);
        } else {
            ordenDeArresto.setVehiculo(Constants.VACIO);
        }
        ordenDeArresto.actualizaListaDeSospechosos();
        
        listaDeSospechososPosibles.setModel(new javax.swing.AbstractListModel() {
            String[] sospechosos = Juego.getInstance().getJugador().getOrdenDeArresto().getArrayDeSospechosos();
            public int getSize() { return sospechosos.length; }
            public Object getElementAt(int i) { return sospechosos[i]; }
        });
        jScrollPane1.setViewportView(listaDeSospechososPosibles);
        
    }                                                                   

    private void botonAtrasActionPerformed(java.awt.event.ActionEvent evt) {                                           
        this.setVisible(Boolean.FALSE);
    }                                          

   
              
}
